# Adogs
# 时间: 2021/7/30 13:43
import pygame
from scene.welcome_sprite import WelcomeSprite
from scene import BaseScene, ScenePassStatus


class WelcomeScene(BaseScene):
    """
    开始场景
    方法:
    1.__init__(xiao_tie)
    2.draw_actor()
    3.run(down_flag, key_list)
    4.get_pass_status()
    """
    def __init__(self, xiao_tie):
        """
        初始化函数
        :param xiao_tie: 欢迎精灵
        """
        super(WelcomeScene, self).__init__(xiao_tie, "resources/picture/welcome/welcome.jpg")
        self.actor = WelcomeSprite(50, 300)

        # 加载开始音乐
        pygame.mixer.music.load("resources/sound/地道战.mp3")
        pygame.mixer.music.play(start=20)

    def draw_actor(self):
        """
        绘制精灵
        :return: 无返回值
        """
        self.actor.draw(self.current_surface, 0, 0)

    def run(self, down_flag, key_list):
        """
        运行函数
        :param down_flag:
        :param key_list:
        :return:
        """
        self.actor.run(down_flag, key_list)
        if self.actor.pos_x > 1100:
            self.pass_status = ScenePassStatus.over
            pygame.mixer.music.stop()
        elif down_flag and key_list[pygame.K_SPACE]:
            self.pass_status = ScenePassStatus.over
            pygame.mixer.music.stop()

    def get_pass_status(self):
        """
        获取场景状态
        :return: 场景状态
        """
        if self.pass_status != ScenePassStatus.over:
            return self.pass_status, None
        else:
            return self.pass_status, "TunnelWarScene"
